/**
 * VUEshop
 * ============================================================================
 * * 版权所有 2015-2027 深圳搜豹网络科技有限公司，并保留所有权利。
 * 网站地址: http://www.vueshop.com.cn
 * ----------------------------------------------------------------------------
 * 这不是一个自由软件！您只能在不用于商业目的的前提下对程序代码进行修改和使用 .
 * 不允许对程序代码以任何形式任何目的的再发布。
 * ============================================================================
 * $Author: soubao-java 2020-07-22 $
 */<template>
  <div>
    <div class="item-title">
      <div class="subject">
        <h3>分销商列表</h3>
        <h5>分销关系管理</h5>
      </div>
    </div>
    <div
      id="explanation"
      class="explanation"
      style="color: rgb(85, 85, 85); background-color: rgb(243, 244, 244); width: 98%; height: 100%;"
    >
      <div class="bckopa-tips">
        <div class="title">
          <img src="@/static/images/handd.png" alt />
          <h4 title="提示相关设置操作时应注意的要点">操作提示</h4>
        </div>
        <ul>
          <li>点击查看操作将显示当前用户上三级分销ID和该用户的下三级分销商数量</li>
          <li>列表可根据用户ID和昵称搜索</li>
          <li>列表中的三级分销商数量可点击, 点击后显示该级别下的会员列表</li>
        </ul>
      </div>
      <span title="收起提示" id="explanationZoom" style="display: block;"></span>
    </div>
    <div class="mDiv">
      <div class="ftitle">
        <h3>分销商列表</h3>
        <h5>(共 {{totalCount}} 条记录)</h5>
      </div>
      <a href @click.prevent="refresh()" class="refresh-date">
        <div title="刷新数据" class="pReload">
          <i class="fa fa-refresh"></i>
        </div>
      </a>
      <div class="searchbox">
        <el-input class="searchinput" v-model="userId" size="small" placeholder="用户ID" clearable />
        <el-input
          class="searchinput"
          v-model="nickname"
          width="10"
          size="small"
          placeholder="用户昵称"
          clearable
        />
        <el-button
          class="searchbtn"
          size="small"
          icon="el-icon-search"
          @click="currentPage = 1;getPage()"
        >搜索</el-button>
      </div>
    </div>
    <div class="tablebox" v-if="tableData">
      <el-table :data="tableData" ref="multipleTable" style="width: 100%;">
        <el-table-column label="编号" prop="user_id" width="120"></el-table-column>
        <el-table-column label="微信昵称" prop="nickname" width="150"></el-table-column>
        <el-table-column label="可用资金" prop="user_money" width="130"></el-table-column>
        <el-table-column label="冻结资金" prop="frozen_money" width="100"></el-table-column>
        <el-table-column label="总分成金额" prop="distribut_money" width="100"></el-table-column>
        <el-table-column label="下线会员总数" prop="lower_sum" width="120"></el-table-column>
        <el-table-column label="一级会员数" width="100">
          <template slot-scope="scope">
            <router-link
              v-if="scope.row.first_leader_count > 0"
              :to="{name:'members_first',params:{first_leader: scope.row.user_id}}"
            >
              {{scope.row.first_leader_count}}&nbsp;
              <label class="fa fa-eye" />
            </router-link>
            <label v-else>{{scope.row.first_leader_count}}</label>
          </template>
        </el-table-column>
        <el-table-column label="二级会员数" width="100">
          <template slot-scope="scope">
            <router-link
              v-if="scope.row.second_leader_count > 0"
              :to="{name:'members_second',params:{second_leader: scope.row.user_id}}"
            >
              {{scope.row.second_leader_count}}&nbsp;
              <label class="fa fa-eye" />
            </router-link>
            <label v-else>{{scope.row.second_leader_count}}</label>
          </template>
        </el-table-column>
        <el-table-column label="三级会员数" width="100">
          <template slot-scope="scope">
            <router-link
              v-if="scope.row.third_leader_count > 0"
              :to="{name:'members_third',params:{third_leader: scope.row.user_id}}"
            >
              {{scope.row.third_leader_count}}
              &nbsp;
              <label class="fa fa-eye" />
            </router-link>
            <label v-else>{{scope.row.third_leader_count}}</label>
          </template>
        </el-table-column>
        <el-table-column label="操作">
          <template slot-scope="scope">
            <el-button-group>
              <router-link :to="{name:'member_details', params:{user_id: scope.row.user_id}}">
                <el-button size="small" icon="el-icon-zoom-in">查看</el-button>
              </router-link>
              <router-link :to="{name:'my_store_manage', params:{user_id: scope.row.user_id}}">
                <el-button size="small" icon="el-icon-shopping-cart-full">微店</el-button>
              </router-link>
            </el-button-group>
          </template>
        </el-table-column>
      </el-table>
      <el-pagination
        background
        class="paginationbox"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="currentPage"
        :page-sizes="[5, 10, 15, 20]"
        :page-size="pageSize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="totalCount"
      ></el-pagination>
    </div>
  </div>
</template>

<script>
import { getDistributor } from "@/utils/api";
export default {
  data() {
    return {
      tableData: [],
      currentPage: this.$route.params.currentPage || 1,
      totalCount: 0,
      pageSize: 10,
      userId: null,
      nickname: null
    };
  },
  components: {},
  created() {
    this.getPage();
  },
  methods: {
    handleSizeChange(e) {
      this.pageSize = e;
      this.getPage();
    },
    handleCurrentChange(e) {
      this.currentPage = e;
      this.getPage();
    },
    getPage() {
      var that = this;
      getDistributor({
        user_id: this.userId,
        nickname: this.nickname,
        is_distribut: true,
        p: that.currentPage,
        size: that.pageSize
      }).then(function(res) {
        res.records.forEach(element => {
          element.distribut_proportion = element.user_money.toFixed(2);
          element.frozen_money = element.frozen_money.toFixed(2);
          element.distribut_money = element.distribut_money.toFixed(2);
        });
        that.tableData = res.records;
        that.totalCount = res.total;
      });
    },
    refresh() {
      this.getPage();
      this.$message({
        type: "success",
        message: "刷新成功！"
      });
    },
    toEdit(storeId) {
      this.$router.push({
        name: "store_edit",
        params: {
          isOwnShop: 1,
          storeId: storeId,
          currentPage: this.currentPage
        }
      });
    }
  }
};
</script>

<style scoped>
.searchinput {
  width: auto;
}
</style>
